package com.controller.search 
{	
	import com.model.valueObjects.VoCancelledSc;
	import com.service.SCSearch;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class SCSearchController extends AbstractController
	{
		
		[Inject]
		public var scSearch:SCSearch;
		
		public function SCSearchController()
		{
			super();
		}
		
		[EventHandler(event="SCSearchEvent.CANCEL_SC",properties="cancelScVo")]
		public function cancelSc(cancelScVo:VoCancelledSc):void{
			sh.executeServiceCall(scSearch.cancelScItem(cancelScVo),cancelScResult, handleFault );
		}
		private function cancelScResult(event:ResultEvent):void
		{
			getRecentScHeader();
			Alert.show(event.result as String,'Info');
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.CANCEL_UNMAPPED_ISC",properties="cancelScVo")]
		public function cancelUnmappedIsc(cancelScVo:VoCancelledSc):void{
			sh.executeServiceCall(scSearch.cancel_Unmapped_Indent_SC(cancelScVo),cancelUnmappedIscResult, handleFault );
		}
		private function cancelUnmappedIscResult(event:ResultEvent):void
		{
			getRecentScHeader();
			Alert.show(event.result as String,'Info');
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.CANCEL_ISC_AND_PO",properties="cancelScVo")]
		public function cancelIscAndPo(cancelScVo:VoCancelledSc):void{
			sh.executeServiceCall(scSearch.cancel_ISC_And_PO(cancelScVo),cancelIscAndPoResult, handleFault );
		}
		private function cancelIscAndPoResult(event:ResultEvent):void
		{
			getRecentScHeader();
			Alert.show(event.result as String,'Info');
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_CANCELLED_SC_HEADER")]
		public function getCancelledScHeader():void{
			sh.executeServiceCall(scSearch.getCancelledScHeader(),getCancelledScHeaderResult, handleFault );
		}		
		private function getCancelledScHeaderResult(event:ResultEvent):void
		{
			model.scSearchHeader = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_CANCELLED_SC_DETAILS",properties="sc_serialnumber")]
		public function getCancelledScDetails(sc_serialnumber:int):void{
			sh.executeServiceCall(scSearch.getCancelledScDetails(sc_serialnumber),getCancelledScDetailsResult, handleFault );
		}		
		private function getCancelledScDetailsResult(event:ResultEvent):void
		{
			model.scSearchDetail = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
								
		[EventHandler(event="SCSearchEvent.GET_RECENT_SC_HEADER")]
		public function getRecentScHeader():void{
			sh.executeServiceCall(scSearch.getRecentSCHeader(),getRecentScHeaderResult, handleFault );
		}		
		private function getRecentScHeaderResult(event:ResultEvent):void
		{
			model.scSearchHeader = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_SC_DETAILS",properties="sc_serialnumber")]
		public function getScDetails(sc_serialnumber:int):void{
			sh.executeServiceCall(scSearch.getSCDetails(sc_serialnumber),getScDetailsResult, handleFault );
		}		
		private function getScDetailsResult(event:ResultEvent):void
		{
			model.scSearchDetail = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_COMPLETED_SC_HEADER")]
		public function getCompletedScHeader():void{
			sh.executeServiceCall(scSearch.getCompletedSCHeader(),getCompletedScHeaderResult, handleFault );
		}		
		private function getCompletedScHeaderResult(event:ResultEvent):void
		{
			model.scSearchHeader = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_COMPLETED_SC_DETAILS",properties="sc_serialnumber")]
		public function getCompletedScDetails(sc_serialnumber:int):void{
			sh.executeServiceCall(scSearch.getCompletedSCDetails(sc_serialnumber),getCompletedScDetailsResult, handleFault );
		}		
		private function getCompletedScDetailsResult(event:ResultEvent):void
		{
			model.scSearchDetail = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_OUTSTANDING_SC_HEADER")]
		public function getOutstandingScHeader():void{
			sh.executeServiceCall(scSearch.getOutstandingSCHeader(),getOutstandingScHeaderResult, handleFault );
		}				
		private function getOutstandingScHeaderResult(event:ResultEvent):void
		{
			model.scSearchHeader = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_OUTSTANDING_SC_DETAILS",properties="sc_serialnumber")]
		public function getOutstandingScDetails(sc_serialnumber:int):void{
			sh.executeServiceCall(scSearch.getOutstandingSCDetails(sc_serialnumber),getOutstandingScDetailsResult, handleFault );
		}		
		private function getOutstandingScDetailsResult(event:ResultEvent):void
		{
			model.scSearchDetail = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_CONFORM_SC_HEADER")]
		public function getConformScHeader():void{
			sh.executeServiceCall(scSearch.getConformedSCHeader(),getConformScHeaderResult, handleFault );
		}		
		private function getConformScHeaderResult(event:ResultEvent):void
		{
			model.scSearchHeader = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_CONFORM_SC_DETAILS",properties="sc_serialnumber")]
		public function getOutConformScDetails(sc_serialnumber:int):void{
			sh.executeServiceCall(scSearch.getConformedSCDetails(sc_serialnumber),getOutConformScDetailsResult, handleFault );
		}		
		private function getOutConformScDetailsResult(event:ResultEvent):void
		{
			model.scSearchDetail = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="SCSearchEvent.GET_DO_LINKS",properties="sc_detserialnumber_fk")]
		public function getDoLinks(sc_detserialnumber_fk:Number):void{
			sh.executeServiceCall(scSearch.getDoLinks(sc_detserialnumber_fk),getDoLinksResult, handleFault );
		}		
		private function getDoLinksResult(event:ResultEvent):void
		{
			model.scSearchDoLinks = event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		private function handleFault(event:FaultEvent):void
		{
			Alert.show( event.fault.faultDetail, "Error" );
		}
	}
}